package com.clt.web.common;

import java.util.ArrayList;
import java.util.List;

import com.clt.web.pojo.WxMenu;

/**
 * 3X3菜单配置转对象方法
 * 
 * @author wenjian
 * 
 */
public class MenuUtil {

	/**
	 * 组装菜单对象
	 * @param basePath 项目路径
	 * @return List<WxMenu>
	 */
	public List<WxMenu> configToBeans(String basePath){
		List<WxMenu> wxMenu = new ArrayList<WxMenu>();
		//组装主菜单
		WxMenu wxMenu1 = new WxMenu();
		wxMenu1.setName(WeiXinMenuPropertiesUtil.getL_main_menu_name());
		wxMenu1.setContent(WeiXinMenuPropertiesUtil.getL_main_menu_url());
		wxMenu1.setContentType(WeiXinMenuPropertiesUtil.getL_main_menu_type());
		
		WxMenu wxMenu2 = new WxMenu();
		wxMenu2.setName(WeiXinMenuPropertiesUtil.getM_main_menu_name());
		wxMenu2.setContent(WeiXinMenuPropertiesUtil.getM_main_menu_url());
		wxMenu2.setContentType(WeiXinMenuPropertiesUtil.getM_main_menu_type());
		
		WxMenu wxMenu3 = new WxMenu();
		wxMenu3.setName(WeiXinMenuPropertiesUtil.getR_main_menu_name());
		wxMenu3.setContent(WeiXinMenuPropertiesUtil.getR_main_menu_url());
		wxMenu3.setContentType(WeiXinMenuPropertiesUtil.getR_main_menu_type());
		// 组装左边主菜单的子菜单
		List<WxMenu> childList1 = new ArrayList<WxMenu>();
		if (null != WeiXinMenuPropertiesUtil.getL_main_menu_url_1()
				&& !"".equals(WeiXinMenuPropertiesUtil.getL_main_menu_url_1())) {
			WxMenu wxMenu11 = new WxMenu();
			wxMenu11.setName(WeiXinMenuPropertiesUtil.getL_main_menu_name_1());
			wxMenu11.setContent(WeiXinMenuPropertiesUtil.getL_main_menu_url_1());
			wxMenu11.setContentType(WeiXinMenuPropertiesUtil.getL_main_menu_type_1());
			childList1.add(wxMenu11);
		}
		if (null != WeiXinMenuPropertiesUtil.getL_main_menu_url_2()
				&& !"".equals(WeiXinMenuPropertiesUtil.getL_main_menu_url_2())) {
			WxMenu wxMenu12 = new WxMenu();
			wxMenu12.setName(WeiXinMenuPropertiesUtil.getL_main_menu_name_2());
			wxMenu12.setContent(WeiXinMenuPropertiesUtil.getL_main_menu_url_2());
			wxMenu12.setContentType(WeiXinMenuPropertiesUtil.getL_main_menu_type_2());
			childList1.add(wxMenu12);
		}
		if (null != WeiXinMenuPropertiesUtil.getL_main_menu_url_3()
				&& !"".equals(WeiXinMenuPropertiesUtil.getL_main_menu_url_3())) {
			WxMenu wxMenu13 = new WxMenu();
			wxMenu13.setName(WeiXinMenuPropertiesUtil.getL_main_menu_name_3());
			wxMenu13.setContent(WeiXinMenuPropertiesUtil.getL_main_menu_url_3());
			wxMenu13.setContentType(WeiXinMenuPropertiesUtil.getL_main_menu_type_3());
			childList1.add(wxMenu13);
		}
		if (childList1.size() > 0) {
			wxMenu1.setChilds(childList1);
		}
		// 组装中间主菜单的子菜单
		List<WxMenu> childList2 = new ArrayList<WxMenu>();
		if (null != WeiXinMenuPropertiesUtil.getM_main_menu_url_1()
				&& !"".equals(WeiXinMenuPropertiesUtil.getM_main_menu_url_1())) {
			WxMenu wxMenu21 = new WxMenu();
			wxMenu21.setName(WeiXinMenuPropertiesUtil.getM_main_menu_name_1());
			wxMenu21.setContent(WeiXinMenuPropertiesUtil.getM_main_menu_url_1());
			wxMenu21.setContentType(WeiXinMenuPropertiesUtil.getM_main_menu_type_1());
			childList2.add(wxMenu21);
		}
		if (null != WeiXinMenuPropertiesUtil.getM_main_menu_url_2()
				&& !"".equals(WeiXinMenuPropertiesUtil.getM_main_menu_url_2())) {
			WxMenu wxMenu22 = new WxMenu();
			wxMenu22.setName(WeiXinMenuPropertiesUtil.getM_main_menu_name_2());
			wxMenu22.setContent(WeiXinMenuPropertiesUtil.getM_main_menu_url_2());
			wxMenu22.setContentType(WeiXinMenuPropertiesUtil.getM_main_menu_type_2());
			childList2.add(wxMenu22);
		}
		if (null != WeiXinMenuPropertiesUtil.getM_main_menu_url_3()
				&& !"".equals(WeiXinMenuPropertiesUtil.getM_main_menu_url_3())) {
			WxMenu wxMenu23 = new WxMenu();
			wxMenu23.setName(WeiXinMenuPropertiesUtil.getM_main_menu_name_3());
			wxMenu23.setContent(WeiXinMenuPropertiesUtil.getM_main_menu_url_3());
			wxMenu23.setContentType(WeiXinMenuPropertiesUtil.getM_main_menu_type_3());
			childList2.add(wxMenu23);
		}
		if (childList2.size() > 0) {
			wxMenu2.setChilds(childList2);
		}
		// 组装右边主菜单的子菜单
		List<WxMenu> childList3 = new ArrayList<WxMenu>();
		if (null != WeiXinMenuPropertiesUtil.getR_main_menu_url_1()
				&& !"".equals(WeiXinMenuPropertiesUtil.getR_main_menu_url_1())) {
			WxMenu wxMenu31 = new WxMenu();
			wxMenu31.setName(WeiXinMenuPropertiesUtil.getR_main_menu_name_1());
			wxMenu31.setContent(WeiXinMenuPropertiesUtil.getR_main_menu_url_1());
			wxMenu31.setContentType(WeiXinMenuPropertiesUtil.getR_main_menu_type_1());
			childList3.add(wxMenu31);
		}
		if (null != WeiXinMenuPropertiesUtil.getR_main_menu_url_2()
				&& !"".equals(WeiXinMenuPropertiesUtil.getR_main_menu_url_2())) {
			WxMenu wxMenu32 = new WxMenu();
			wxMenu32.setName(WeiXinMenuPropertiesUtil.getR_main_menu_name_2());
			wxMenu32.setContent(WeiXinMenuPropertiesUtil.getR_main_menu_url_2());
			wxMenu32.setContentType(WeiXinMenuPropertiesUtil.getR_main_menu_type_2());
			childList3.add(wxMenu32);
		}
		if (null != WeiXinMenuPropertiesUtil.getR_main_menu_url_3()
				&& !"".equals(WeiXinMenuPropertiesUtil.getR_main_menu_url_3())) {
			WxMenu wxMenu33 = new WxMenu();
			wxMenu33.setName(WeiXinMenuPropertiesUtil.getR_main_menu_name_3());
			wxMenu33.setContent(WeiXinMenuPropertiesUtil.getR_main_menu_url_3());
			wxMenu33.setContentType(WeiXinMenuPropertiesUtil.getR_main_menu_type_3());
			childList3.add(wxMenu33);
		}
		if (childList3.size() > 0) {
			wxMenu3.setChilds(childList3);
		}
		// 统一将菜单加到菜单对象中
		if (wxMenu1.getChilds().size() > 0||(null!=wxMenu1.getContent()&&!"".equals(wxMenu1.getContent()))) {
			wxMenu.add(wxMenu1);
		}
		if (wxMenu2.getChilds().size() > 0||(null!=wxMenu2.getContent()&&!"".equals(wxMenu2.getContent()))) {
			wxMenu.add(wxMenu2);
		}
		if (wxMenu3.getChilds().size() > 0||(null!=wxMenu3.getContent()&&!"".equals(wxMenu3.getContent()))) {
			wxMenu.add(wxMenu3);
		}
		return wxMenu;
	}
}
